package models

import (
	"time"
	"reflect"
	"github.com/astaxie/beego/validation"
)

type Staff struct{
	Id int `orm:"auto"`
	Company_id int `form:"company_id" valid:"Required" validmsg:"请选择公司"`
	Name string `form:"name" valid:"Required" validmsg:"请输入姓名"`
	Phone string `form:"phone" valid:"Required" validmsg:"请输入联系方式"`
	Identity string `form:"identity"`
	Address string `form:"address"`
	Type int `form:"type" valid:"Required" validmsg:"请选择添加类型"`
	In_party_at time.Time `form:"in_party_at" orm:"type(datetime)"`
	Lat string `form:"lat"`
	Lng string `form:"lng"`
	Created_at time.Time `orm:"auto_now_add;type(datetime)"`
	Updated_at time.Time `orm:"auto_now"`
	Deleted_at time.Time `orm:"type(datetime)"`
}

func (this *Staff)Valid()(b bool ,str string ){
	v:=validation.Validation{}
	b,_=v.Valid(this)
	if !b {
		st:=reflect.TypeOf(Staff{})
		field,_:=st.FieldByName(v.Errors[0].Field)
		msg:=field.Tag.Get("validmsg")
		return b,msg
	}
	return true,""
}